package thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * Description: CountDownLatch的使用
 * User: 王圆豪
 * Date: 2025-05-08
 * Time: 13:31
 */
public class Demo39 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch count = new CountDownLatch(10);
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        for (int i = 0; i < 10; i++) {
            int id = i;
            executorService.submit(()->{
                System.out.println(Thread.currentThread().getName() + "正在执行任务" + id);
                count.countDown();
            });
        }
        count.await();
        executorService.shutdown();
    }
}
